<?php
	defined('_JEXEC') or die('Restricted access');
    require_once(CUTEENGINE_BASE_COMPONENTS_PATH."base_tag_class.php");
    require_once(CUTEENGINE_NAMESPACES_PATH."javascript_namespace.php");
	
    /********** 
            t_editing_tags
            
         **********/
	class t_editing_tags extends t_base_tag
	{	
        //const declaration
        //public 
		const ancor_postfix_name =':ancor';
        //P
        const postfix_name ='_editing_tags';

        // property declaration 
        // public
        // A
        public $associated_tag = false;
		// method declaration
		// public
        public function __construct($a_associated_tag,$a_visible = false) 
		{
            global $g_javascript_namespace;
            //
            parent::__construct(t_base_tag_type::btt_div,
				$a_associated_tag->name.self::postfix_name);
			// proper style
			$this->add_style_property("z-index","2000");			
			
            // associated_tag
            $this->associated_tag = $a_associated_tag;
            $this->associated_tag->add_event($this->associated_tag->name,
				'onmousemove','activate_selection_tags',$this->delayed_position);
			// ancor div
			
			$local_ancor_tag = $this->create_and_add_child_at_bottom(t_base_tag_type::btt_div,$this->name.self::ancor_postfix_name);
		//	$local_ancor_tag->add_property('onclick','activate_editing_tags();');
			$local_ancor_tag->add_property('onmousemove','activate_selection_tags(event,'.t_cuteengine::javascript_instance_name.'.html_tag(\''.$this->associated_tag->name.'\'))');
            $local_ancor_tag->class_name = $tag_image_moving_class_name;
			$local_ancor_tag->add_style_property("width","10px");
			$local_ancor_tag->add_style_property("height","10px");
			$local_ancor_tag->add_style_property("z-index","2001");
			$local_ancor_tag->add_style_property("visibility","visible");
			$local_ancor_tag->add_style_property("display","block");
			$local_ancor_tag->add_style_property("position","relative");
			$local_ancor_tag->add_style_property("background-color","cornflowerblue");
            $this->set_moving_and_sizing_tags(true);
			//javascript
			//$this->associated_tag->add_event($this->name,'onclick','activate_editing_tags',$this->delayed_position,'event');
			$this->add_property('onclick','activate_editing_tags();');
			
			$g_javascript_namespace->header_script_generator->add_function_to_main_scope(
                "activate_selection_tags","e,a_sender","
            if (e == null){e = window.event;}
            if (a_sender == undefined)
				var local_sender = (typeof( window.event ) != \"undefined\" ) ? e.srcElement : e.target;
			else
				var local_sender = a_sender;
            local_current_component_inspector = ".t_cuteengine::javascript_instance_name.".component_inspector;
            if (local_current_component_inspector != undefined)
            {
                if ((local_sender.id != undefined) && (local_sender.id.indexOf('".self::ancor_postfix_name."') > -1))
					local_current_component_inspector.activate_selection_tag(local_sender.parentNode,local_sender.parentNode.id);
				else
					local_current_component_inspector.activate_selection_tag(local_sender,local_sender.id+'".self::postfix_name."');
			}");
            $g_javascript_namespace->header_script_generator->add_function_to_main_scope(
                "activate_editing_tags","e","
            if (e == null){e = window.event;}
            var local_sender = (typeof( window.event ) != \"undefined\" ) ? e.srcElement : e.target;
            local_current_component_inspector = ".t_cuteengine::javascript_instance_name.".component_inspector;
            if (local_current_component_inspector != undefined)
            {
                if ((local_sender.id != undefined) && (local_sender.id.indexOf('".self::ancor_postfix_name."') > -1))
					local_current_component_inspector.activate_editing_tag(local_sender.parentNode,local_sender.parentNode.id+'".self::postfix_name."');
				else
					local_current_component_inspector.activate_editing_tag(local_sender,local_sender.id+'".self::postfix_name."');                					
            }");
		    //
            $g_javascript_namespace->header_script_generator->add_function_to_main_scope(
                "set_as_editor","a_sender","
            a_sender.style.backgroundColor = 'lightSalmon';
			this.html_tag(\"".$this->moving_and_sizing_tags->name."\").style.visibility = '';");
            //
            $g_javascript_namespace->header_script_generator->add_function_to_main_scope(
                "set_as_selection","a_sender","
            a_sender.style.backgroundColor = 'lightYellow';
			this.html_tag(\"".$this->moving_and_sizing_tags->name."\").style.visibility = 'hidden';");
            
			// style
            $this->class_name = "editing_tags_class_style";
			if ($a_visible == false)
				$this->add_style_property("visibility","hidden");
            //echo "$this->name: ".method_exists($this->header_script_generator,add_style_sheet_property)." <BR>";
            /*$g_javascript_namespace*/$this->header_script_generator->add_style_sheet_property(".$this->class_name",'background-color','lightSalmon');
            
			//$this->header_script_generator->add_style_sheet_property(".$this->class_name",'border','5px dashed Gold');
        }
		
		// G
		public function get_javascript_function_script()
		{
            global $g_cuteengine;
			$local_optimize_javascript_code = $g_cuteengine->get_main_query_parameter_value(
				t_cuteengine_component::main_query_component_optimize_javascript_code);
			if ($local_optimize_javascript_code === true)
			{
			}
			else
			{	
				return "local_tag = document.getElementById(\"".$this->moving_and_sizing_tags->name."\"); this[\"".$this->moving_and_sizing_tags->name."\"] = local_tag;";
			}
		}
	}	
?>